package org.hhttp.core;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class Constants {
	
	private static Logger logger = Logger.getLogger(Constants.class);
	
	public static String SESSION_ID = "JSESSIONID";
	
	public static int thread_pool_maxnum = 10;
	public static int thread_pool_initnum = 5;
	public static int thread_pool_keepalivetime = 20;
	public static int object_poll_num = 6;
	static {
		Properties properties = new Properties();
		try {
			
			InputStream resourceAsStream = Constants.class.getResourceAsStream("/app.properties");
			properties.load(resourceAsStream);
			thread_pool_maxnum = Integer.parseInt(getProperty(properties,"threadpool.maxnum"));
			thread_pool_initnum = Integer.parseInt(getProperty(properties,"threadpool.initnum"));
			thread_pool_keepalivetime = Integer.parseInt(getProperty(properties,"threadpool.keepalivetime"));
			object_poll_num = Integer.parseInt(getProperty(properties,"objectpoll.num"));
		} catch (Exception e) {
			logger.fatal("load properties error:" + e);
		}
	}

	private static String getProperty(Properties properties,String key){
		
		String value = properties.getProperty(key);
		if(value == null){
			logger.fatal("Missing config key:" + key);
		}
		return value;
	}
}
